- https://stripe.com/docs/billing/subscriptions/subscription-schedules?lang=php
- https://gitlab.com/publicala/general/-/issues/275
For anual subscriptions
// Set your secret key. Remember to switch to your live secret key in production!
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey('sk_test_c454q235v245345v345345cd');
\Stripe\SubscriptionSchedule::create([
'customer' => 'cus_1ludjafghu923da',
'start_date' => 'now',
'end_behavior' => 'release',
'phases' => [
[
'plans' => [
[
'plan' => 'price_13123123124413',
'quantity' => 1,
],
],
'coupon' => 'dfadsfadf',
'iterations' => 1,
],
[
'plans' => [
[
'plan' => 'price_13123123124413',
'quantity' => 1,
],
],
'coupon' => 'qwerfqfew',
'iterations' => 1,
],
[
'plans' => [
[
'plan' => 'price_13123123124413',
'quantity' => 1,
],
],
'iterations' => 1,
],
],
]);
For monthly subscriptions
\Stripe\Stripe::setApiKey('as');
\Stripe\SubscriptionSchedule::create([
'customer' => 'cus_asdasdasdasd',
'start_date' => 'now',
'end_behavior' => 'release',
'phases' => [
[
'plans' => [
[
'plan' => 'price_ui23t4g12i3ug123b1jk231hn2m3',
'quantity' => 1,
],
],
'coupon' => '23123asd',
'iterations' => 12,
],
[
'plans' => [
[
'plan' => 'price_ui23t4g12i3ug123b1jk231hn2m3',
'quantity' => 1,
],
],
'coupon' => '123131ed',
'iterations' => 12,
],
[
'plans' => [
[
'plan' => 'price_ui23t4g12i3ug123b1jk231hn2m3',
'quantity' => 1,
],
],
'iterations' => 12,
],
],
]);
For monthly subscriptions and adding the offline app as a second product in that subscription
\Stripe\Stripe::setApiKey('as');
\Stripe\SubscriptionSchedule::create([
'customer' => 'cus_asdasdasdasd',
'start_date' => 'now',
'end_behavior' => 'release',
'phases' => [
[
'plans' => [
[
'plan' => 'price_ui23t4g12i3ug123b1jk231hn2m3',
'quantity' => 1,
],
[
'plan' => 'price_1HAzUNKABeXPc2SH3wbIOcKE12kg',
'quantity' => 1,
],
],
// In this case, the coupon might have a condition so that Stripe only applies to the plan and not the app
'coupon' => '23123asd',
'iterations' => 12,
],
[
'plans' => [
[
'plan' => 'price_ui23t4g12i3ug123b1jk231hn2m3',
'quantity' => 1,
],
[
'plan' => 'price_1HAzUNKABeXPc2SH3wbIOcKE12kg',
'quantity' => 1,
],
],
// In this case, the coupon might have a condition so that Stripe only applies to the plan and not the app
'coupon' => '123131ed',
'iterations' => 12,
],
[
'plans' => [
[
'plan' => 'price_ui23t4g12i3ug123b1jk231hn2m3',
'quantity' => 1,
],
[
'plan' => 'price_1HAzUNKABeXPc2SH3wbIOcKE12kg',
'quantity' => 1,
],
],
'iterations' => 12,
],
],
]);
Create a subscription schedule from a regular subscription
\Stripe\SubscriptionSchedule::create([
'from_subscription' => 'sub_GgzqRJGAo61zbq',
]);
Mofify a subscription schedule to end the current phase and start a new one, we can end the phase in a particular moment in the future
\Stripe\SubscriptionSchedule::update('sub_sched_1HXB1uKABeXPc2SHqOgpC2K3', [
'phases' => [
[
'plans' => [
[
'plan' => 'price_HMVI6nQJLJoLoo',
'quantity' => 1,
],
],
'coupon' => 'mMSK49M7',
'start_date' => 1601493824,
'end_date' => 1632987120,
],
[
'plans' => [
[
'plan' => 'price_HMVI6nQJLJoLoo',
'quantity' => 1,
],
],
'coupon' => 'w7PS9jIt',
'iterations' => 1,
],
[
'plans' => [
[
'plan' => 'price_HMVI6nQJLJoLoo',
'quantity' => 1,
],
],
'iterations' => 1,
],
],
]);
Create a subscription schedule from a regular subscription
- End the current phase in a particular moment
- Add 3 phases with teared discounts
- Add the app as a product in all phases
\Stripe\Stripe::setApiKey('___sk_live___');
\Stripe\Subscription::retrieve('sub_ELbhvpKyeEPW6l');
\Stripe\SubscriptionSchedule::create([
'from_subscription' => 'sub_ELbhvpKyeEPW6l',
]);
\Stripe\SubscriptionSchedule::retrieve('sub_sched_1I1N8jKABeXPc2SHUhc2LST0');
\Stripe\SubscriptionSchedule::update('sub_sched_1I1N8jKABeXPc2SHUhc2LST0', [
'phases' => [
[
'plans' => [
[
'plan' => 'price_HMWIJZmlQuzOcb',
'quantity' => 1,
],
],
// In this case, the coupon might have a condition so that Stripe only applies to the plan and not the app
'coupon' => 'PsvAlvyn',
'start_date' => 1579104612,
'end_date' => 1610727012,
],
[
'plans' => [
[
'plan' => 'price_HMWRks6v27irCT',
'quantity' => 1,
],
[
'plan' => 'price_1HAzUOKABeXPc2SHoEseJRqR',
'quantity' => 1,
],
],
// In this case, the coupon might have a condition so that Stripe only applies to the plan and not the app
'coupon' => 'TEUqtPZB',
'iterations' => 1,
],
[
'plans' => [
[
'plan' => 'price_HMWRks6v27irCT',
'quantity' => 1,
],
[
'plan' => 'price_1HAzUOKABeXPc2SHoEseJRqR',
'quantity' => 1,
],
],
// In this case, the coupon might have a condition so that Stripe only applies to the plan and not the app
'coupon' => 'k7LyijnD',
'iterations' => 1,
],
[
'plans' => [
[
'plan' => 'price_HMWRks6v27irCT',
'quantity' => 1,
],
[
'plan' => 'price_1HAzUOKABeXPc2SHoEseJRqR',
'quantity' => 1,
],
],
'coupon' => 'josYnM7x'
],
],
]);